﻿ <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="http://schemas.startreksupremacy.com/xaml/core"
                    xmlns:xs="http://schemas.startreksupremacy.com/xaml/core/markup"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    xmlns:local="clr-namespace:Supremacy.Client"
                    xmlns:Views="clr-namespace:Supremacy.Client.Views"
                    mc:Ignorable="d">

  <local:FormatStringConverter x:Key="FormatStringConverter" />
  <SolidColorBrush x:Key="GreenLightStroke" Color="#FF006400" />

  <RadialGradientBrush x:Key="GreenLightFill" GradientOrigin="0.5,0.5" RadiusY="0.5" RadiusX="0.5">
    <GradientStop Color="#FF00FF00" Offset="0" />
    <GradientStop Color="#FF008C00" Offset="1" />
  </RadialGradientBrush>

  <SolidColorBrush x:Key="RedLightStroke" Color="#FF640000" />

  <RadialGradientBrush x:Key="RedLightFill" GradientOrigin="0.5,0.5" RadiusY="0.5" RadiusX="0.5">
    <GradientStop Color="#FFFF0000" Offset="0" />
    <GradientStop Color="#FF8C0000" Offset="1" />
  </RadialGradientBrush>

  <Style x:Key="BuildShipButton"
           TargetType="{x:Type Button}">
    <Setter Property="Focusable" Value="False"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="UseLayoutRounding" Value="True" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="ToolTip" Value="Build a Ship" />
    <Setter Property="Width" Value="48" />
    <Setter Property="Height" Value="48" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Border>
            <Image x:Name="ImageContent" Source="vfs:///Resources/UI/Federation/ColonyScreen/build_ship.png" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center" />
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
              <Setter TargetName="ImageContent" Property="Effect">
                <Setter.Value>
                  <DropShadowEffect Color="Violet" BlurRadius="5" ShadowDepth="0" RenderingBias="Quality" Direction="270" />
                </Setter.Value>
              </Setter>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
              <Setter TargetName="ImageContent" Property="Margin" Value="2" />
              <Setter TargetName="ImageContent" Property="Width" Value="44" />
              <Setter TargetName="ImageContent" Property="Height" Value="44" />
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="CancelShipConstructionButton"
           TargetType="{x:Type Button}">
    <Setter Property="Focusable" Value="False"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="UseLayoutRounding" Value="True" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="ToolTip" Value="Build a Ship" />
    <Setter Property="Width" Value="48" />
    <Setter Property="Height" Value="48" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Border x:Name="ShipBorder" BorderBrush="White" BorderThickness="2" CornerRadius="3" Background="#AF000000">
            <Image x:Name="ShipImage" Width="84" Stretch="Uniform" HorizontalAlignment="Center" VerticalAlignment="Center"
                       Cursor="Hand">
              <Image.ToolTip>
                <MultiBinding Converter="{x:Static local:FormatStringConverter.Instance}" ConverterParameter="{xs:LocalizedString Group={x:Static s:LocalizedTextGroups.ColonyScreen}, Entry=SHIP_CONSTRUCTION_PROJECT_TOOLTIP}">
                  <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ShipyardDockView}}" Path="(local:ShipyardDockView.BuildSlot).(s:BuildSlot.Project).(s:BuildProject.BuildDesign).(s:TechObjectDesign.Name)" Mode="OneWay" />
                  <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ShipyardDockView}}" Path="(local:ShipyardDockView.BuildSlot).(s:BuildSlot.Project).(s:BuildProject.BuildDesign).(s:ShipDesign.ClassName)" Mode="OneWay" />
                  <Binding RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ShipyardDockView}}" Path="(local:ShipyardDockView.BuildSlot).(s:BuildSlot.Project).(s:BuildProject.PercentComplete)" StringFormat="0.%"  Mode="OneWay" />
                </MultiBinding>
              </Image.ToolTip>
            </Image>
          </Border>
          <ControlTemplate.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ShipyardDockView}}, Path=(local:ShipyardDockView.BuildSlot).(s:BuildSlot.HasProject), Mode=OneWay}"
                         Value="True">
              <Setter TargetName="ShipBorder" Property="Visibility" Value="Visible" />
              <Setter TargetName="ShipImage" Property="Source" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ShipyardDockView}}, Path=(local:ShipyardDockView.BuildSlot).(s:BuildSlot.Project).(s:BuildProject.BuildDesign).(s:TechObjectDesign.Image), Mode=OneWay}" />
            </DataTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style x:Key="ToggleConstructionBayButton"
           TargetType="{x:Type Button}">
    <Setter Property="Focusable" Value="False"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="Foreground" Value="White"/>
    <Setter Property="FontFamily" Value="Futura MdCn BT" />
    <Setter Property="FontSize" Value="16" />
    <Setter Property="UseLayoutRounding" Value="True" />
    <Setter Property="Cursor" Value="Hand" />
    <Setter Property="Width" Value="24" />
    <Setter Property="Height" Value="Auto" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Button}">
          <Border x:Name="OuterBorder" CornerRadius="3" BorderThickness="1">
            <Border.Background>
              <RadialGradientBrush GradientOrigin="0.5,0.333333" RadiusY="0.666667" RadiusX="1">
                <GradientStop Color="#FFC8C8C8" Offset="0" />
                <GradientStop Color="#FF646464" Offset="1" />
              </RadialGradientBrush>
            </Border.Background>
            <Border.BorderBrush>
              <RadialGradientBrush GradientOrigin="0.5,0.333333" RadiusY="0.666667" RadiusX="1">
                <GradientStop Color="#FF969696" Offset="0" />
                <GradientStop Color="#FF323232" Offset="1" />
              </RadialGradientBrush>
            </Border.BorderBrush>
            <StackPanel>
              <Ellipse x:Name="PowerIndicator" Width="12" Height="12" Margin="0,6,0,0" Stroke="{StaticResource RedLightStroke}" StrokeThickness="1" Fill="{StaticResource RedLightFill}" />
              <Path Width="15" Height="21" Margin="0,3,0,0" Stretch="Uniform" Fill="#FFFFFF00" Data="F1 M 20,0L 2,16L 8,16L 0,28L 18,12L 12,12L 20,0 Z "/>
              <TextBlock FontSize="12" Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ShipyardDockView}}, Path=(local:ShipyardDockView.BuildSlot).(s:ShipyardBuildSlot.Shipyard).(s:Shipyard.ShipyardDesign).(s:ShipyardDesign.BuildSlotEnergyCost)}" HorizontalAlignment="Center" Margin="0,0,0,3" />
            </StackPanel>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="IsPressed" Value="True">
              <Setter TargetName="OuterBorder" Property="Margin" Value="1,1,-1,-1" />
            </Trigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ShipyardDockView}}, Path=(local:ShipyardDockView.BuildSlot).(s:ShipyardBuildSlot.IsActive), Mode=OneWay}"
                         Value="True">
              <Setter TargetName="PowerIndicator" Property="Stroke" Value="{StaticResource GreenLightStroke}" />
              <Setter TargetName="PowerIndicator" Property="Fill" Value="{StaticResource GreenLightFill}" />
            </DataTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <Style TargetType="{x:Type local:ShipyardDockView}">

    <Style.Resources>


      <DrawingImage x:Key="StopwatchImage">
        <DrawingImage.Drawing>
          <DrawingGroup>
            <DrawingGroup.Children>
              <GeometryDrawing Geometry="F1 M 8.98201,0L 12.3094,0C 12.5465,0 12.7388,0.192139 12.7388,0.429281L 12.7388,2.36141C 12.7388,2.59847 12.5465,2.79069 12.3094,2.79069L 11.483,2.79069L 11.483,3.6617C 13.8805,3.85685 16.0431,4.88216 17.683,6.44971L 18.152,5.98063L 17.871,5.69979C 17.7257,5.55444 17.7257,5.31877 17.871,5.1735L 19.3181,3.72648C 19.4634,3.58114 19.699,3.58114 19.8443,3.72648L 21.2914,5.1735C 21.4367,5.31877 21.4367,5.55444 21.2914,5.69979L 19.8443,7.14681C 19.699,7.29215 19.4634,7.29215 19.3181,7.14681L 18.9413,6.7701L 18.4472,7.26424C 19.9354,9.03508 20.8318,11.3198 20.8318,13.814C 20.8318,19.4395 16.2713,24 10.6458,24C 5.02018,24 0.459717,19.4395 0.459717,13.814C 0.459717,11.3442 1.33862,9.07983 2.80078,7.31649L 2.30225,6.81795L 1.97339,7.14681C 1.82804,7.29215 1.59245,7.29215 1.44718,7.14681L 0,5.69979C -0.145264,5.55444 -0.145264,5.31877 0,5.1735L 1.44718,3.72648C 1.59245,3.58114 1.82804,3.58114 1.97339,3.72648L 3.42049,5.1735C 3.56576,5.31877 3.56576,5.55444 3.42049,5.69979L 3.09155,6.02856L 3.55965,6.49658C 5.20532,4.90259 7.38721,3.8588 9.80859,3.6617L 9.80859,2.79069L 8.98201,2.79069C 8.74495,2.79069 8.55273,2.59847 8.55273,2.36141L 8.55273,0.429281C 8.55273,0.192139 8.74495,0 8.98201,0 Z M 10.6458,5.86043C 6.25317,5.86043 2.69222,9.42139 2.69222,13.814C 2.69222,18.2065 6.25317,21.7674 10.6458,21.7674C 15.0383,21.7674 18.5992,18.2065 18.5992,13.814C 18.5992,9.42139 15.0383,5.86043 10.6458,5.86043 Z M 11.5059,14.9882C 10.7975,15.6966 9.64901,15.6966 8.94059,14.9882C 8.23218,14.2798 8.23226,13.1313 8.94067,12.4229C 9.40601,11.9576 10.0612,11.7979 10.6568,11.9439L 15.4524,8.47624L 11.9849,13.2719C 12.1309,13.8675 11.9713,14.5229 11.5059,14.9882 Z ">
                <GeometryDrawing.Brush>
                  <RadialGradientBrush RadiusX="0.557898" RadiusY="0.5" Center="0.499998,0.500003" GradientOrigin="0.499998,0.500003">
                    <RadialGradientBrush.GradientStops>
                      <GradientStop Color="#FFFFFF00" Offset="0"/>
                      <GradientStop Color="#FFFFC800" Offset="1"/>
                    </RadialGradientBrush.GradientStops>
                    <RadialGradientBrush.RelativeTransform>
                      <TransformGroup/>
                    </RadialGradientBrush.RelativeTransform>
                  </RadialGradientBrush>
                </GeometryDrawing.Brush>
              </GeometryDrawing>
            </DrawingGroup.Children>
          </DrawingGroup>
        </DrawingImage.Drawing>
      </DrawingImage>

    </Style.Resources>

    <Setter Property="Foreground" Value="White"/>
    <Setter Property="FontFamily" Value="Futura MdCn BT" />
    <Setter Property="FontSize" Value="16" />
    <Setter Property="TextBlock.Foreground" Value="White"/>
    <Setter Property="TextBlock.FontFamily" Value="Futura MdCn BT" />
    <Setter Property="TextBlock.FontSize" Value="16" />

    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:ShipyardDockView}">
          <DockPanel>
            <Button x:Name="PowerButton" Style="{StaticResource ToggleConstructionBayButton}" DockPanel.Dock="Left" Width="24" VerticalAlignment="Top" Margin="0,3,0,0" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Views:ColonyScreenView}, Path=DataContext.(Views:ColonyScreenPresentationModel.ToggleShipyardBuildSlotCommand)}" CommandParameter="{Binding}">
              <Button.ToolTip>
                <MultiBinding Converter="{x:Static local:FormatStringConverter.Instance}" ConverterParameter="{xs:LocalizedString Group={x:Static s:LocalizedTextGroups.ColonyScreen}, Entry=TOGGLE_CONSTRUCTION_BAY_BUTTON_TOOLTIP_OFFLINE}">
                  <Binding Path="(s:ShipyardBuildSlot.Shipyard).(s:Shipyard.ShipyardDesign).(s:ShipyardDesign.BuildSlotEnergyCost)" Mode="OneWay" />
                </MultiBinding>
              </Button.ToolTip>
            </Button>
            <Grid x:Name="ResourcesSite" DockPanel.Dock="Right" Margin="12,0,0,0" Opacity="0.33" Visibility="Hidden">
              <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
              </Grid.ColumnDefinitions>
              <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
              </Grid.RowDefinitions>
              <Image Grid.Row="0" Source="vfs:///Resources/Images/Resources/RawMaterials.png" Width="24" ToolTip="{xs:EnumString {x:Static s:ResourceType.RawMaterials}}" />
              <Image Grid.Row="1" Source="vfs:///Resources/Images/Resources/Deuterium.png" Width="24" ToolTip="{xs:EnumString {x:Static s:ResourceType.Deuterium}}" />
              <Image Grid.Row="2" Source="vfs:///Resources/Images/Resources/Dilithium.png" Width="24" ToolTip="{xs:EnumString {x:Static s:ResourceType.Dilithium}}" />
              <Image Grid.Row="3" Source="{StaticResource StopwatchImage}" Width="17" ToolTip="{xs:LocalizedString Group={x:Static s:LocalizedTextGroups.ColonyScreen}, Entry=SHIP_CONSTRUCTION_TIME_TOOLTIP}" />

              <!-- Invisible text to avoid shifting layouts -->
              <TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0" Text="999 / 999" Visibility="Hidden" />
              <TextBlock Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0" Text="999 / 999" Visibility="Hidden" />
              <TextBlock Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0" Text="999 / 999" Visibility="Hidden" />
              <TextBlock Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0" Visibility="Hidden">
                <TextBlock.Text>
                  <Binding Source="999"
                           BindsDirectlyToSource="True"
                           StringFormat="{xs:LocalizedString Group={x:Static s:LocalizedTextGroups.ColonyScreen}, Entry=TURNS_UNTIL_COMPLETION_FORMAT}"
                           Mode="OneTime" />
                </TextBlock.Text>
              </TextBlock>

              <TextBlock Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0">
                <TextBlock.Text>
                  <MultiBinding StringFormat="{}{0} / {1}">
                     <Binding Path="(s:BuildSlot.Project).(s:BuildProject.ResourcesInvested)[RawMaterials]" Mode="OneWay" />
                     <Binding Path="(s:BuildSlot.Project).(s:BuildProject.BuildDesign).(s:TechObjectDesign.BuildResourceCosts)[RawMaterials]" Mode="OneWay" />
                  </MultiBinding>
                </TextBlock.Text>
              </TextBlock>
              <TextBlock Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0">
                <TextBlock.Text>
                  <MultiBinding StringFormat="{}{0} / {1}">
                     <Binding Path="(s:BuildSlot.Project).(s:BuildProject.ResourcesInvested)[Deuterium]" Mode="OneWay" />
                     <Binding Path="(s:BuildSlot.Project).(s:BuildProject.BuildDesign).(s:TechObjectDesign.BuildResourceCosts)[Deuterium]" Mode="OneWay" />
                  </MultiBinding>
                </TextBlock.Text>
              </TextBlock>
              <TextBlock Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0">
                <TextBlock.Text>
                  <MultiBinding StringFormat="{}{0} / {1}">
                     <Binding Path="(s:BuildSlot.Project).(s:BuildProject.ResourcesInvested)[Dilithium]" Mode="OneWay" />
                     <Binding Path="(s:BuildSlot.Project).(s:BuildProject.BuildDesign).(s:TechObjectDesign.BuildResourceCosts)[Dilithium]" Mode="OneWay" />
                  </MultiBinding>
                </TextBlock.Text>
              </TextBlock>
              <TextBlock Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Margin="8,0,0,0">
                <TextBlock.Text>
                  <Binding Path="(s:BuildSlot.Project).(s:BuildProject.TurnsRemaining)"
                           StringFormat="{xs:LocalizedString Group={x:Static s:LocalizedTextGroups.ColonyScreen}, Entry=TURNS_UNTIL_COMPLETION_FORMAT}"
                           Mode="OneWay" />
                </TextBlock.Text>
              </TextBlock>
            </Grid>
            <Grid x:Name="ImageSite" Width="225" Opacity="0.33">
              <Image Source="vfs:///Resources/UI/Federation/ColonyScreen/shipyard_dock.png" />
              <Button x:Name="CancelButton" Style="{StaticResource CancelShipConstructionButton}" Width="96" Height="72" HorizontalAlignment="Center" VerticalAlignment="Center" Visibility="Hidden" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Views:ColonyScreenView}, Path=DataContext.(Views:ColonyScreenPresentationModel.CancelBuildProjectCommand)}" CommandParameter="{Binding Path=(s:BuildSlot.Project)}" />
              <Button x:Name="BuildShipButton" Style="{StaticResource BuildShipButton}" Width="48" Height="48" Margin="0,16,0,0" Visibility="Hidden" ToolTip="{xs:LocalizedString Group={x:Static s:LocalizedTextGroups.ColonyScreen}, Entry=BUILT_NEW_SHIP_TOOLTIP}" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Views:ColonyScreenView}, Path=DataContext.(Views:ColonyScreenPresentationModel.SelectShipBuildProjectCommand)}" CommandParameter="{Binding}" />
            </Grid>
          </DockPanel>

          <ControlTemplate.Triggers>

            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(local:ShipyardDockView.BuildSlot).(s:BuildSlot.HasProject), Mode=OneWay}"
                         Value="True">
              <Setter TargetName="CancelButton" Property="Visibility" Value="Visible" />
              <Setter TargetName="ResourcesSite" Property="Visibility" Value="Visible" />
            </DataTrigger>

            <MultiDataTrigger>
              <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding Path=(s:BuildSlot.HasProject), Mode=OneWay}" Value="False" />
                <Condition Binding="{Binding Path=(s:ShipyardBuildSlot.IsActive), Mode=OneWay}" Value="True" />
              </MultiDataTrigger.Conditions>
              <Setter TargetName="BuildShipButton" Property="Visibility" Value="Visible" />
            </MultiDataTrigger>

            <DataTrigger Binding="{Binding Path=(s:ShipyardBuildSlot.IsActive), Mode=OneWay}"
                         Value="True">
              <Setter TargetName="PowerButton" Property="ToolTip">
                <Setter.Value>
                  <MultiBinding Converter="{x:Static local:FormatStringConverter.Instance}" ConverterParameter="{xs:LocalizedString Group={x:Static s:LocalizedTextGroups.ColonyScreen}, Entry=TOGGLE_CONSTRUCTION_BAY_BUTTON_TOOLTIP_ONLINE}">
                    <Binding Path="(s:ShipyardBuildSlot.Shipyard).(s:Shipyard.ShipyardDesign).(s:ShipyardDesign.BuildSlotEnergyCost)" Mode="OneWay" />
                  </MultiBinding>
                </Setter.Value>
              </Setter>
              <Setter TargetName="ResourcesSite" Property="Opacity" Value="1" />
              <Setter TargetName="ImageSite" Property="Opacity" Value="1" />
            </DataTrigger>

          </ControlTemplate.Triggers>

        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ResourceDictionary>
